#ifndef __COMET_H__
#define __COMET_H__

#include "headers.h"
#include "User.h"
#include "func.h"

using namespace std;

class User;

class Comet {
public:
	Comet(const string& cfgFile);
	~Comet();

	User* getUser(const string& username);
	bool addUser(const string& username);
	bool delUser(const string& username);
	bool startRunning();
	void stopRunning() {running = false; }

	static int getTimeoutMillSec() {
		return timeoutMillSec;
	}
	// defines msg types
	const static string MSGTYPE_RECV;
	const static string MSGTYPE_SEND;
	const static string MSGTYPE_DEL;
private:
	bool initialize();

	string cfgFile;
	map<string, User*> users;

	SOCKET sockSvr;
	SOCKET fd;	// save the last socket fd for thread

	// parameters
	int port;
	int blocks;
	static int timeoutMillSec;

	bool running;

friend void handleClient(void*);
};

#endif
